﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoMcCoffee\ControlerBase.cs
// Author : Sohobloo
// Create time : 2014/02/09 20:00
// Update time : 2014/02/16 15:28

#endregion

#region 引用

using System;
using System.ComponentModel.Composition;
using System.Web.Mvc;
using Sohobloo.SoCommon;
using Sohobloo.SoCommon.Log;

#endregion

namespace Sohobloo.SoMcCoffee.Mvc
{
    public abstract class MvcControllerBase : Controller, ILoggable
    {
        [Import]
        public ILogger Logger { get; set; }

        protected OperationResult TryExecute(Func<OperationResult> func)
        {
            OperationResult result;
            try
            {
                result = func();
            }
            catch(Exception ex)
            {
                result = new OperationResult(OperationResultType.Error);
                this.LogError(ex);
            }

            return result;
        }
    }
}